const ws = new WebSocket("ws://127.0.0.1:8080")

//上线
ws.onopen = function () {
    ws.send("我上线啦")
}

//发送消息
ws.onmessage = function (msg) {
    console.log(msg);
    //js原生语法从页面DOM对象中动态获取说话的内容
    const content = document.getElementById("content").value
    content.innerHTML = msg.data + "<br>"
}
//报错
ws.onerror = (err) =>{
    console.log(err);
}
//下线
ws.onclose =  ()=> {
    console.log("close");
}